﻿@model IEnumerable<ExtMember>

@{
    ViewData["Title"] = "成员列表";
}

<div class="content-top-nav">
    <h3 style="color:#444"><i class="layui-icon layui-icon-home"></i>@ViewData["Title"] </h3>
    <hr>
</div>
<div class="layui-fluid" style="margin-bottom:50px;">
     <div class="layui-card">
        <form class="layui-form" action="" lay-filter="FormSearch" enctype="multipart/form-data">
            <div class="layui-card-body ">
                <div class="layui-form">
                     <div class="layui-inline layui-show-xs-block" style="width:80px;" >
                        <select id="status" name="status" lay-verify="">
                            <option value="">全部</option>
                            <option value="1">在岗</option>
                            <option value="0">离岗</option>
                        </select>
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="name" id="keyword" placeholder="按姓名搜索" class="layui-input" style="width:150px;">
                    </div>

                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" data-type="reload" id="searchBtn"><i class="layui-icon">&#xe615;</i></button>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <script type="text/html" id="toolbarAE">
                <div class="layui-btn-container">
                    @if (CheckExt.AuthView(ViewBag.sr, "extmember_addoredit"))
                    {
                        <button class="layui-btn layui-btn-sm data-add-btn">新增</button>
                    }
                </div>
            </script>

            <table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>
     <script type="text/html" id="statusTpl">
        {{# if(d.status == 1){  }}
        <div style="color: #0d8e03">在岗</div>
        {{# }else{ }}
        <div style="color: #FF5722">离岗</div>
        {{# } }}
    </script>
    <script type="text/html" id="imgTpl">
       <img src="{{d.photo}}" style="width:50px;height:30px;"/>
    </script>
            <script type="text/html" id="currentTableBar">
                @if (CheckExt.AuthView(ViewBag.sr, "extmember_addoredit"))
                {
                    <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                }
                @if (CheckExt.AuthView(ViewBag.sr, "extmember_delete"))
                {
                    <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
                }
            </script>
        </div>
    </div>
</div>
<script>
    layui.use(['table','jquery','util','form'], function () {
        var table = layui.table,$ = layui.jquery,util = layui.util, form = layui.form;
         form.render();
       var tableIns = table.render({
            elem: '#currentTableId',
            url: '/Admin/ExtMember/Index?json=1',
            toolbar: '#toolbarAE',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                { field: 'id', width: 80, title: 'ID', sort: true },
                { field: 'name', width: 100, title: '姓名', unresize: true },
                { field: 'duties',  title: '负责工作' },
                { field: 'photo', width: 80, title: '照片' ,templet:"#imgTpl" },
                { field: 'duty', title: '职务' },
                { field: 'sort', width: 140, title: '排序(可编辑)', sort: true, edit: 'text' },
                { field: 'status', width: 100, title: '状态', sort: true, unresize: true,templet:"#statusTpl" },
                { title: '操作', width: 160, templet: '#currentTableBar', fixed: "right", align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 5,
            id: 'tableReload',
            page: true
        });

        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            loadMain('/Admin/ExtMember/AddOrEdit');
            return false;
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                loadMain('/Admin/ExtMember/AddOrEdit?&id=' + data.id);
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('删除确认？', function (index) {
                    $.post('/Admin/ExtMember/Delete?id=' + data.id,function (res) {
                        if (res.status == 1) {
                            layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                obj.del();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                        }
                    });
                });
            }
        });

        //监听单元格编辑
        table.on('edit(currentTableFilter)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            $.post('/Admin/ExtMember/EditPost?dyEdit=1&id=' + data.id, {Sort:value}, function (res) {
                table.reload('tableReload');
            });
        });

        //搜索重载表格
        $('#searchBtn').on('click', function () {
             tableIns.reload({
                 method: 'get',
                 where: {
                     name: $('#keyword').val(),
                     status: $('#status').val(),
                 },
                 page: {
                     curr: 1
                 },
                 page: true,
             });
             return false;
        });
         
    });
</script>